<template>
	<view class="jobDetailPage">
		<view class="jobCard  mL15 mR15">
			<view class="w100">
				<text class="jobName   font20 bold u-3 ">{{info?.oddJobName}}</text>
				<u-tag :text="info?.izUrgentText" bg-color="#fff" class="jpTag" :color="'#FF0000'"
					:border-color="'#FF0000'" v-show="info?.izUrgent==1" />
				<u-tag v-if="info?.recruitmentCarefree&&info?.recruitmentCarefree.indexOf('10')>=0" text="用工无忧"
					bg-color="#EAF4FE" class="zgTag" :color="'#3291F8'" :border-color="'#EAF4FE'" />
			</view>

			<view class="flex alg-center mT5">
				<view class="jobTime">{{info?.jobBeginDatetime}}-{{info?.jobEndDatetime}}</view>
				<view class="jobTime">{{info?.salaryPaymentText}}</view>
				<view class="jobTime">招{{info?.oddJobUseNum}}人</view>
			</view>
			<view class="flex jst-between alg-center">
				<view class="">
					<text class="font24 u-red bold">{{info?.salary}}</text>
					<text class="u-red font14 bold">元</text>
				</view>
				<view class="font13 ua">
					发布于{{info?.timediffStr}}
				</view>
			</view>
			<view class="mT10">
				<view class="flex alg-center jst-between mT5">
					<view class="flex  w80">
						<u-image :width="32" :height="32" :src="resources.posIcon" mode=""></u-image>
						<view class="u-8bd font13 pL5 posTextw">
							{{info?.hopeWorkAddress}}
						</view>
					</view>

					<view class="u-6 font13">
						{{info?.distance}}
					</view>
				</view>
			</view>

		</view>
		<view class="mL15 mR15 pT15 pB15">
			<view class="flex jst-between">
				<text class="font17" v-if="define.identification=='units'">合适人员信息</text>
				<text class="font17" v-else>求职者</text>
				<view class="flex alg-center"
					@click="xf.onlineUtils.route(`pages/common/morePerson/index?jobId=${jobId}`)">
					<text class="font13 u-8bd mR5">查看更多</text>
					<u-icon :size="24" name="arrow-right" class="u-8bd"></u-icon>
				</view>
			</view>

		</view>
		<mescroll-uni class="lisBox" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
			:down="downOption" :up="upOption" :bottombar="false" :top="topH">
			<workerJob :list="list" @confirm="grabOpt"></workerJob>
		</mescroll-uni>
	
		<xfTipModal ref="tipModal"></xfTipModal>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {
		getHsUserLis,
		grabDetail,
		workJober
	} from '@/api/companyInterface/job.js'
	import {getUserLis} from "@/api/economicInterface/user.js"
	import workerJob from "@/components/company/jobCard/index.vue"
	import {getLocal} from "@/libs/map.js"
	export default {
		mixins: [MescrollMixin],
		components: {
			workerJob
		},
		watch: {
			info() {
				if (this.flagSetH == true) {
					this.$nextTick(() => {
						this.getElementScollTop()
						this.flagSetH = false;
						console.log(this.flagSetH)
					})
				}
			},
		},
		data() {
			return {
				loading: false,
				id: null,
				showModal: false,
				info: null,
				tx: null,
				latitude: null,
				longitude: null,
				list: [],
				topH: 0,
				flagSetH: true,
				downOption: {
					use: true,
					auto: false
				},
				upOption: {
					page: {
						num: 0,
						size: 10,
						time: null
					},
					empty: {
						use: true,
						icon: '/static/image/nodata.png',
						tip: "暂无数据",
						fixed: true
					},
					textNoMore: "到底啦~",
				},
			};
		},
		onLoad(e) {
			this.jobId = e.id;
			this.getDetail(this.jobId)
		},
		methods: {
			//获取滚动框距离顶部距离
			getElementScollTop() {
				const query = uni.createSelectorQuery()
				query.select('.lisBox').boundingClientRect((data) => {
						this.topH = Math.round(data.top)+'px'
						console.log(this.topH)
					}).exec()
			},
			//派单
			grabOpt(v) {
				let that = this;
				this.$refs.tipModal.open({
					btnText: "派单给Ta",
					content: "确认派单给Ta吗？",
					showCancel: true,
					success: function() {
						uni.showLoading()
						//由于企业端与经纪人端调用的是两个接口，且返回的用户id对应的key 不一样需要处理
						workJober([{
							"xfOddGeneralId":that.define.identification=='units'?v.xfOddUserId:v.id,
							"oddjobInfoId": that.info?.id,
							"isGrab": "1"
						}]).then(res => {
							uni.hideLoading()
							that.$nextTick(()=>{
								uni.showToast({
									icon: 'none',
									title: "派单成功!",
									duration: 2000
								})
							})
						
						})
					}
				})
			},
			async upCallback(page) {
				if (page.num == 1) this.list = [];
				let pageNo = page.num;
				const {lat,lon} = await this.xf.getLatOrLon();
				//判断是企业端 还是经纪人端
				let func =this.define.identification=='units'?getHsUserLis:getUserLis
				func({
					latitude: lat,
					longitude: lon,
					pageSize: 10,
					pageNo: pageNo
				}).then(res => {
					let list = res.result.records;
					this.list = this.list.concat(list);
					this.mescroll.endSuccess(res.result.records.length);
				}).catch(err => {
					this.mescroll.endByPage(0, 0);
					this.mescroll.endSuccess(1);
					this.mescroll.endErr();
				})
			},	
			async getDetail(id) {
				this.info=null;
				const {
					lat,
					lon
				} = await this.xf.getLatOrLon();
				grabDetail({
					infoId: id,
					latitude: lat,
					longitude: lon
				}).then(res => {
					
					this.info = res.result
				})
			}

		}
	};
</script>
<style lang="scss">
	page {
		min-height: 100%;
		background: linear-gradient(0deg, #F8FAFF, #EBF0FF);
		/* #ifdef MP-ECONOMIC */
		background: linear-gradient(0deg, #F8FAFF, #EBFCFF);
		/* #endif */
		
	}
</style>
<style scoped lang="scss">
	.jgGs {
		border-bottom: 2rpx solid #F6F6F6;
	}

	.rightImg {
		width: 9rpx;
		height: 18rpx;
	}

	.phoneImg {
		width: 48rpx;
		height: 48rpx;
		margin: 0 auto;
	}

	.posBox {
		border-top: 2rpx solid #F6F6F6;
	}

	.companyInfo {
		width: calc(100% - 110rpx);
	}

	.jobCard {
		padding: 20rpx 30rpx;
		margin-bottom: 20rpx;
		background: #FFFFFF;
		border-radius: 20rpx;

		.jobLeft {
			max-width: 70%;
		}

		.jobStatus {
			border: 2rpx solid #FF0000;
			border-radius: 10rpx;
			height: 34rpx;
			line-height: 34rpx;
			padding: 0 10rpx;
			margin-right: 10rpx;
		}

		.jobTag {
			height: 34rpx;
			line-height: 34rpx;
			padding: 0 10rpx;
			background: #F8F8F8;
			border-radius: 6rpx;
		}

		.jobMoney {
			word-break: keep-all;
		}

		.jobTime {
			color: #8D8D8D;
			font-size: 26rpx;
			margin-right: 10rpx;
			height: 44rpx;
			line-height: 44rpx;
			padding: 0 10rpx;
			background: #F8F8F8;
			border-radius: 6rpx;
			margin-top: 16rpx;
		}

		.posImg {
			width: 32rpx;
			height: 32rpx;
		}

		.posTxt {
			width: calc(100% - 42rpx);
			font-weight: 400;
			font-size: 26rpx;
			color: #8D8D8D;
		}

		.companyImg {
			width: 48rpx;
			height: 48rpx;
		}

		.rzImg {
			width: 24rpx;
			height: 24rpx;
		}

		.companyName {
			font-weight: 500;
			font-size: 30rpx;
			color: #333;
			margin-right: 10rpx;
			margin-left: 10rpx;
		}
	}
</style>